package cz.proks.easyhelpdesk.gae.core.db;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import cz.proks.easyhelpdesk.api.UserApi;
import cz.proks.easyhelpdesk.api.config.Configuration;
import cz.proks.easyhelpdesk.api.exception.ApiException;
import cz.proks.easyhelpdesk.api.model.User;

@Component(Configuration.Core.DB.USER_API)
public class UserApiImpl extends BaseApiImpl<User> implements UserApi {
	private final Logger log = LoggerFactory.getLogger(getClass());
	
	@Autowired
	@Qualifier(Configuration.DB.USER_API)
	private UserApi dbApi;

	@Override
	protected UserApi getDbApi() {
		return dbApi;
	}

    @Override
    public User getForProvider(String providerId) throws ApiException {
        log.debug("getForProvider():: Start with providerId '{}'", providerId);
        
        User user = getDbApi().getForProvider(providerId);
        
        log.debug("getForProvider():: Exit with entity '{}'", user);
        return user;
    }		
    
    @Override
    public List<User> listForHelpdesk(Long helpdeskId) throws ApiException {
        log.debug("listForHelpdesk():: Start with helpdeskId '{}'", helpdeskId);
        
        List<User> users = getDbApi().listForHelpdesk(helpdeskId);
        
        log.debug("listForHelpdesk():: Exit with {}", (users == null ? "null list" : "list of " + users.size() + " members"));
        return users;
    }           
}
